const http = require("http");
const fs = require("fs");
const path = require("path");

http.createServer((req, res) => {
    if (req.url == "/") {
        var filePath = path.join(__dirname, "./test.html");
        var readable = fs.readFileSync(filePath);
        res.writeHead(200, { "Content-Type": "text/html" });
        res.write(readable);
        res.end();
    } else if (req.url == "/getdata") {
        var arr = [
            { userName: "zhangsan", age: 20 },
            { userName: "lisi", age: 30 },
        ];
        var jsonString = JSON.stringify(arr);
        res.writeHead(200, { "Content-Type": "text/plain" });
        res.write(jsonString);
        res.end();
    }
}).listen(8083);
console.log("listening on");
